package com.xique.common.core.utils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @author caogq
 * @Date: 2021/6/19 11:23
 * @Description:
 */
public class MathUtil {
    /**
     * 生成随机数
     * @param number 需要生成的位数
     * @return
     */
    public static String getRandom(int number){
        Random random = new Random();
        String result="";
        for (int i=0;i<number;i++)
        {
            result+=random.nextInt(10);
        }
        return result;
    }

    public static List<String> convertLongToStringList(List<Long> ids) {
        List<String> strIds = new ArrayList<>();
        for (Long id : ids) {
            strIds.add(String.valueOf(id));
        }
        return strIds;
    }

    public static double div(double v1, double v2, int scale) {
        BigDecimal bigDecimal1 = new BigDecimal(Double.toString(v1));
        BigDecimal bigDecimal2 = new BigDecimal(Double.toString(v2));
        return bigDecimal1.divide(bigDecimal2, scale, BigDecimal.ROUND_HALF_UP).doubleValue();
    }

}
